package com.sunday.common.netty.e8_Handlerorder.server;


import com.sunday.common.netty.e8_Handlerorder.server.inbound.InBoundHandler1;
import com.sunday.common.netty.e8_Handlerorder.server.inbound.InBoundHandler2;
import com.sunday.common.netty.e8_Handlerorder.server.inbound.InBoundHandler3;
import com.sunday.common.netty.e8_Handlerorder.server.inbound.InBoundWritingHandler;
import com.sunday.common.netty.e8_Handlerorder.server.outbound.OutBoundHandler1;
import com.sunday.common.netty.e8_Handlerorder.server.outbound.OutBoundHandler2;
import com.sunday.common.netty.e8_Handlerorder.server.outbound.OutBoundHandler3;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.AbstractNioByteChannel;
import io.netty.util.concurrent.EventExecutor;

public class HandlerOrderTcpServerChannel extends ChannelInitializer {

    @Override
    protected void initChannel(Channel ch) throws Exception {
        /**
         * addFirst 方法可以将一个Handler添加到Pipeline的最前面，也就是第一个Handler的前面。
         * addLast 方法可以将一个Handler添加到Pipeline的最后面，也就是最后一个Handler的后面。
         * addBefore 方法可以在指定的Handler前面添加一个Handler。
         * addAfter 方法可以在指定的Handler后面添加一个Handler。
         *
         * {@link io.netty.channel.AbstractChannelHandlerContext#skipContext(AbstractChannelHandlerContext, EventExecutor, int, int)}
         * {@link io.netty.channel.AbstractChannelHandlerContext#findContextInbound(int)}
         * {@link AbstractNioByteChannel.NioByteUnsafe#read()}
         */
        ch.pipeline()
                .addLast(new OutBoundHandler1())
                .addLast(new OutBoundHandler2())
                .addLast(new OutBoundHandler3())
                .addLast(new InBoundHandler1())
                .addLast(new InBoundHandler2())
                .addLast(new InBoundHandler3())
                .addLast(new InBoundWritingHandler());

    }
}